package com.probiz.estore.product.service.impl;

import java.util.ArrayList;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.probiz.estore.product.ProductConstants;
import com.probiz.estore.product.service.ProdMainManager;
import com.probiz.estore.product.service.ProdMainNtManager;

public class ProdMainNtManagerImpl implements ProdMainNtManager{
	protected final Log logger = LogFactory.getLog(getClass());
	
	private ProdMainManager prodMainManager;
	
	public void setProdMainManager(ProdMainManager prodMainManager) {
		this.prodMainManager = prodMainManager;
	}

	/*
	 * (non-Javadoc)
	 * @see com.probiz.estore.product.service.ProdMainNtManager#doRecordViewCount(java.lang.Integer, javax.servlet.http.HttpSession)
	 * 原理:把客户查看过的所有商品的id作为session的一个值L（List<Integer>）保存起来，如果当前查看的id被包含在L中则忽略，否则把id记录在L中，同时增加商品浏览次数
	 */
	public void doRecordViewCount(Integer productId, HttpSession session) {
		List<Integer> viewProductIdList = (List<Integer>)session.getAttribute(ProductConstants.VIEW_PRODUCT_ID_LIST);
    	if(null == viewProductIdList){
    		viewProductIdList = new ArrayList<Integer>();
    	}
    	if(!viewProductIdList.contains(productId)){
    		viewProductIdList.add(productId);
    		try{
    			prodMainManager.doIncreaseOneViewCount(productId);
    		}catch(Exception e){
    			logger.error(this, e);
    		}
    		session.setAttribute(ProductConstants.VIEW_PRODUCT_ID_LIST, viewProductIdList);
    	}
	}
	
}
